<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<c:set var="buttons">
    <input type="button" style="margin-right: 5px"   onclick="f_add()" value="<fmt:message key="button.add"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_update()" value="<fmt:message key="button.update"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_delete()" value="<fmt:message key="button.delete"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_cancel()" value="<fmt:message key="button.cancel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_save()" value="<fmt:message key="button.save"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_query()" value="<fmt:message key="button.query"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_roles()" value="<fmt:message key="button.roles"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_updatePassword()" value="<fmt:message key="button.updatePassword"/>"/>
<c:if test='${not empty model.parentId}'>
    <input type="button" style="margin-right: 5px"   onclick="f_back()" value="<fmt:message key="button.back"/>"/>
</c:if>
</c:set>
<div id='toolbar' style="display:none">
<c:out value="${buttons}" escapeXml="false"/>
</div>
<div id='password_win'></div>
<script>
Ext.onReady(globalScope._ready);

var passwordWin,passwordForm;
Ext.onReady(function(){
   passwordForm=new Ext.form.FormPanel({
	  	defaultType:'textfield',
	  	labelAlign:'right',
	  	frame:true,
	  	autoHeight:true,
	  	url:g_rootPath+"security/updatePassword.html",
	  	items:[{
	  	  fieldLabel:'新密码',
	  	  id:'newPassword',
	  	  inputType:'password'
	  	},{
	  	  fieldLabel:'重复新密码',
	  	  id:'',
	  	  inputType:'password'
	  	},{
	  	  id:'userName',
	  	  inputType:'hidden'
	  	}]
	  });
  passwordWin= new Ext.Window({
    id:'c_win2',
    el:'password_win',
	title:'修改密码',
    width:300,
    height:g_height*.27,
    closeAction:'hide',
    buttonAlign:'center',
    items: [passwordForm],
    buttons:[{
       text:'<fmt:message key="button.conf"/>',
	   handler:function(){
	     passwordForm.getForm().submit({
	       success:function(form,action){
	         Ext.Msg.alert("提示信息",action.result.info);
	         passwordForm.getForm().reset();
	       },
	       failure:function(form,action){
	         Ext.Msg.alert("提示信息","修改密码发生错误:"+action.result.info);
	         passwordForm.getForm().reset();
	       }
	     });
	     passwordWin.hide();
	   }
    },{
       text:'<fmt:message key="button.close"/>',
	   handler:function(){
	     passwordWin.hide();
	   }
    }]
  })
  passwordWin.render(document.body);  
});

function f_updatePassword(tableName){
      tableName=globalScope.getTableName(tableName);
	  var r=globalScope.grid.get(tableName).getSelectionModel().getSelected();
	  if(Ext.isEmpty(r)){
	    Ext.Msg.alert('WARNING','<fmt:message key="info.required_update_record"/>');
	    return;
	  }
	 passwordForm.getForm().findField("userName").setValue(r.get("USERNAME"));
     passwordWin.show();
}

function f_roles(){
  var r=globalScope.grid.get("APP_USER").getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING','请选择用户');
    return;
  }
  var id=r.id;
   var matrix=[["tableName","V_USER_ROLE"],["USER_ID",id]];
   var form=createForm("<c:url value='/quick/quickWithParentInfo.html'/>",matrix);
   form.submit();
}


function f_add(tableName){
  globalScope._add(tableName);
}

function f_update(tableName){
  globalScope._update(tableName);
}

function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(){
  tableName="<c:out value='${model.tableName}' escapeXml='false'/>";
  globalScope._simpleSave({
            tableName:tableName,
            url:"/security/appUserProcess.html",
            _afterSave:function(response,gridColumns){
                 var resp=Ext.decode(response.responseText);
	             Ext.quick.reformatGridTable(globalScope.grid.get(tableName),gridColumns,resp[1].idJson);
			     globalScope.delRecs.add(tableName,[]);
		         Ext.Msg.alert('<fmt:message key="label.info"/>',resp[0],function(){});
            }});
}

function f_query(tableName){
    globalScope._query(tableName);
}
function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  globalScope._gotoPage({spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"});
}
</script>
